package tcp_ip;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;

public class SocketServer {
	public static void main(String[] args) {
		try {
			ServerSocket socket = new ServerSocket(4444);
			byte[] receiveBuff = new byte[32];
			int offset;
			while(true) {
				Socket client = socket.accept();
				
				SocketAddress clientAddress = client.getRemoteSocketAddress();
				System.out.println("Handling client at: " + clientAddress);
				BufferedReader r = new BufferedReader(new InputStreamReader(client.getInputStream()));
				OutputStream out = client.getOutputStream();
				String s;
				while ((s = r.readLine()) != null) {
					System.out.println("server recieved: " + s);
				}
//				out.write(s != null ? s.getBytes() : "No input".getBytes());
				client.close();
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
